<?php 

/**
 * 订单控制器
 */
class OrderController extends AuthController{
    private $model;
	
	public function __init(){
	    parent::__init();
		$this->model = K('Order');
	}
	 /**
     * 
     */
    public function index(){
    		$data = M()->join("__order__ o JOIN __user__ u ON o.user_uid=u.uid")->all();
    		$this->assign('data', $data);
       	$this->display(); 
    }
	
	public function delivering(){
	    $data = M()->join("__order__ o JOIN __user__ u ON o.user_uid=u.uid")->where("status='待发货'")->all();
    		$this->assign('data', $data);
       	$this->display();
	}
	
	public function delivered(){
	    $data = M()->join("__order__ o JOIN __user__ u ON o.user_uid=u.uid")->where("status='已发货'")->all();
    		$this->assign('data', $data);
       	$this->display();
	}
	
	public function finished(){
	    $data = M()->join("__order__ o JOIN __user__ u ON o.user_uid=u.uid")->where("status='已完成'")->all();
    		$this->assign('data', $data);
       	$this->display();
	}
	
	public function canceled(){
	    $data = M()->join("__order__ o JOIN __user__ u ON o.user_uid=u.uid")->where("status='已取消'")->all();
    		$this->assign('data', $data);
       	$this->display();
	}
	
	public function edit(){
	    $this->display();
	}
	
	// 删除订单
	public function del(){
	    $oid = Q('get.oid', 0, 'intval');
		if (!$this->model->delData($oid)){
			$this->error($this->model->error);
		}
		$this->success('删除订单成功', U('Index'));
	}
	
	// 取消订单
	public function cancel(){
	    $oid = Q('get.oid', 0, 'intval');
		if (!$this->model->cancelData($oid)){
			$this->error($this->model->error);
		}
		$this->success('取消订单成功');		
	}
	
	// 设置订单为已发货
	public function deliver(){
	    $oid = Q('get.oid', 0, 'intval');
		if (!$this->model->deliverData($oid)){
			$this->error($this->model->error);
		}
		$this->success('设置订单已发货成功');		
	}
	
	// 设置订单为已完成
	public function finish(){
	    $oid = Q('get.oid', 0, 'intval');
		if (!$this->model->finishData($oid)){
			$this->error($this->model->error);
		}
		$this->success('设置订单已完成成功');		
	}
 }
 
 
 
 
 
 
 
 
 
 
 


 ?>